#include<iostream>
#include<pthread.h>
#include<string>
#include<unistd.h>
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond=PTHREAD_COND_INITIALIZER;
void* active(void*arg){
    std::string name=static_cast<char*>(arg);
    while(true){
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond,&mutex);
        printf("%s is active\n",name.c_str());
        pthread_mutex_unlock(&mutex);
    }
}
int main(){
    pthread_t tid1,tid2,tid3,tid4,tid5,tid6,tid7;
    pthread_create(&tid1,nullptr,active,(void*)"thread-1");
    pthread_create(&tid2,nullptr,active,(void*)"thread-2");
    pthread_create(&tid3,nullptr,active,(void*)"thread-3");
    pthread_create(&tid4,nullptr,active,(void*)"thread-4");
    pthread_create(&tid5,nullptr,active,(void*)"thread-5");
    pthread_create(&tid6,nullptr,active,(void*)"thread-6");
    pthread_create(&tid7,nullptr,active,(void*)"thread-7");
    sleep(1);
    printf("Main thread begin\n");

    while(true){
        pthread_cond_signal(&cond);
        printf("Main thread wake cond\n");
        sleep(1);
    }
    pthread_join(tid1,nullptr);
    pthread_join(tid2,nullptr);
    pthread_join(tid3,nullptr);
    
}